import com.yumeko.dao.ResumeDao;
import com.yumeko.pojo.Resume;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;
import java.util.Optional;

/**
 * @program: ssp
 * @description:
 * @author: Zheng Hao
 * @create: 2020-01-14 23:42
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"classpath*:applicationContext*.xml"})
public class textClass {
    @Autowired
    private ResumeDao resumeDao;
    @Test
    public void testDoLogin(){
        Resume resume = new Resume();
        resume.setUserName("admin");
        resume.setPassword("admin");
        Resume resume1 = resumeDao.findByUserNameAndPassword(resume.getUserName(),resume.getPassword());
        System.out.println(resume1);
    }

    @Test
    public void testFindAll(){
        Sort sort = new Sort(Sort.Direction.ASC, "userId");
        Pageable pageable = PageRequest.of(1, 2, sort);
        Iterable<Resume> resume = resumeDao.findAll(pageable);
        for (Resume resume1 : resume) {
            System.out.println(resume1);
        }
    }

    @Test
    public void testInsert(){
        Resume resume = new Resume();
        resume.setUserName("yumeko");
        resume.setPassword("yumeko");
        Integer resume1 = resumeDao.InsetResume(resume.getUserName(),resume.getPassword());
        System.out.println(resume1);
        Iterable<Resume> resume3 = resumeDao.findAll();
        for (Resume resume2 : resume3) {
            System.out.println(resume2);
        }
    }

    @Test
    public void testUpdate(){
        Resume resume = new Resume();
        resume.setUserId(2);
        resume.setUserName("yumeko");
        resume.setPassword("zhenghao");
        Integer resume1 = resumeDao.UpdateResume(resume.getUserId(),resume.getUserName(),resume.getPassword());
        System.out.println(resume1);
        Iterable<Resume> resume3 = resumeDao.findAll();
        for (Resume resume2 : resume3) {
            System.out.println(resume2);
        }
    }
    @Test
    public void testDelete(){
        Resume resume = new Resume();
        resume.setUserId(3);
        resumeDao.deleteById(resume.getUserId());
    }
}
